/***************************************************************************
 *   KShootout - online shootout card game.                                *
 *   Copyright (C) 2008, 2009  MacJariel                                   *
 *                                                                         *
 *   KShootout is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   KShootout is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with KShootout.  If not, see <http://www.gnu.org/licenses/>.    *
 ***************************************************************************/
#ifndef __CARDWIDGETSIZEMGR_H__
#define __CARDWIDGETSIZEMGR_H__

#include <QObject>
#include <QVector>
#include <QSize>
#include "clienttypes.h"

class QWidget;

namespace client
{
    /**
     * The CardWidgetSizeMgr singleton class manages the size of CardWidgets.
     * @author MacJariel
     */
    class CardWidgetSizeMgr: public QObject
    {
        Q_OBJECT;
    public:
        /// Returns a pointer to the singleton CardWidgetSizeMgr instance.
        static CardWidgetSizeMgr* instance();

        /// Returns the size of CardWidget for given CardSizeRole.
        QSize cardSize(CardSizeRole) const;

        /// Returns the y coordinate of character card to mark given <i>livePoints</i>.
        /// @note This value should be stored in CardSets in the future.
        int lifeLevel(int lifePoints) const;

    public slots:
        void cardSizeUp();
        void cardSizeDown();

    signals:
        /// This signal is emitted when card size is changed. Each CardWidget (and
        /// widgets that use CardWidget size to compute its own size) should connect
        /// to this signal.
        void cardSizeChanged();

    private:
        CardWidgetSizeMgr();
        int width(int height);

        QVector<QSize> m_sizes;

        static qreal sm_cardRatio;
        static qreal sm_lifePointCardRatio[];
    };

    inline CardWidgetSizeMgr* CardWidgetSizeMgr::instance()
    {
        static CardWidgetSizeMgr singleton;
        return &singleton;
    }

    inline QSize CardWidgetSizeMgr::cardSize(CardSizeRole role) const
    {
        return m_sizes.at(role);
    }
}

#endif // __CARDWIDGETSIZEMGR_H__